#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef struct SNode {
    char data;
    struct SNode* next;
} LinkStrNode, *LinkString;

void StrAssign(LinkStrNode **s, char cstr[]) {
    int i;
    LinkStrNode *r, *p;
    *s = (LinkStrNode *)malloc(sizeof(LinkStrNode));  // 创建头结点
    r = *s;
    for (int i = 0; cstr[i] != '\0'; i++) {
        p = (LinkStrNode *)malloc(sizeof(LinkStrNode));
        p->data = cstr[i];
        r->next = p;
        r = p;  // 尾插法，p始终指向尾结点
    }
    r->next = NULL;
}

LinkStrNode *Concat(LinkStrNode *s, LinkStrNode *t) {
    LinkStrNode *str, *p=s->next, *q,*r;
    str = (LinkStrNode *)malloc(sizeof(LinkStrNode));  // 创建头结点
    r = str; //r指向结果串的尾结点
    while(p != NULL) { // 用p扫描s的所有数据结点
        q = (LinkStrNode *)malloc(sizeof(LinkStrNode));
        q->data = p->data;
        r->next = q;
        r = q;
        p = p->next;
    }
    p = t->next;
    while (p != NULL) {
        q = (LinkStrNode *)malloc(sizeof(LinkStrNode));
        q->data = p->data;
        r->next = q;
        r = q;
        p = p->next;
    }
    r->next = NULL;
    return str;
}

bool StrEqual(LinkStrNode *s, LinkStrNode *t) {
    LinkStrNode *p = s->next, *q = t->next; // p，q分别扫描链串s和t的数据结点
    while(p != NULL && q != NULL && p->data == q->data) {
        p = p->next;
        q = q->next;
    }
    if(p == NULL && q == NULL) 
        return true;
    else 
        return false;
}

void PrintStr(LinkStrNode *s) {
    while (s->next) {
        printf("%c", s->next->data);
        s = s->next;
    }
    printf("\n");
}